package com.jim.healio.graphrag.model;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import java.util.Map;
import java.util.HashMap;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class MedicalRelationship {
    
    /**
     * 关系唯一标识
     */
    private String id;
    
    /**
     * 源实体ID
     */
    private String sourceEntityId;
    
    /**
     * 目标实体ID  
     */
    private String targetEntityId;
    
    /**
     * 关系类型
     */
    private RelationshipType type;
    
    /**
     * 关系描述
     */
    private String description;
    
    /**
     * 关系强度/置信度
     */
    private double strength = 1.0;
    
    /**
     * 关系属性
     */
    private Map<String, Object> properties = new HashMap<>();
    
    /**
     * 创建时间戳
     */
    private long createdAt = System.currentTimeMillis();
    
    /**
     * 数据来源
     */
    private String source;
    
    /**
     * 关系类型枚举
     */
    public enum RelationshipType {
        CAUSES("导致"),
        TREATS("治疗"), 
        INDICATES("表示"),
        INTERACTS_WITH("相互作用"),
        PART_OF("属于"),
        ASSOCIATED_WITH("关联"),
        CONTRAINDICATED("禁忌"),
        SIDE_EFFECT("副作用"),
        DOSAGE("剂量"),
        COMPLICATION("并发症"),
        RISK_FACTOR("风险因素"),
        DIAGNOSED_BY("诊断方法"),
        PREVENTS("预防");
        
        private final String description;
        
        RelationshipType(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
    
    /**
     * 便捷构造方法
     */
    public MedicalRelationship(String sourceEntityId, String targetEntityId, 
                              RelationshipType type, String description) {
        this.sourceEntityId = sourceEntityId;
        this.targetEntityId = targetEntityId;
        this.type = type;
        this.description = description;
        this.id = generateId();
    }
    
    /**
     * 生成关系ID
     */
    private String generateId() {
        return String.format("%s_%s_%s", 
            sourceEntityId, type.name(), targetEntityId);
    }
} 